#pragma once

#include "../../vmath/vec2i.h"
#include "../../vmath/vec2.h"
#include "../event/key_event.h"
#include "../event/mouse_event.h"
#include <vector>
#include <string>

OPEN_JLIB_NS


struct GLView {

  struct Listener {
    virtual ~Listener () = default;

    virtual void onClose () = 0;
    virtual void onResize (Vec2i size) = 0;
    virtual void onResume () = 0;
    virtual void onPause () = 0;

    virtual void onMousePress (MouseEvent::Button code) = 0;
    virtual void onMouseRelease (MouseEvent::Button code) = 0;
    virtual void onMouseMove (Vec2 location) = 0;
    virtual void onMouseEnter () = 0;
    virtual void onMouseLeave () = 0;
    virtual void onMouseScroll (Vec2 offset) = 0;

    virtual void onKeyPress (KeyEvent::Key code) = 0;
    virtual void onKeyRepeat (KeyEvent::Key code) = 0;
    virtual void onKeyRelease (KeyEvent::Key code) = 0;

    virtual void onTouchDown (s32 id, Vec2 location) = 0;
    virtual void onTouchMove (const std::vector<s32> &ids, const std::vector<Vec2> &locations) = 0;
    virtual void onTouchUp (s32 id, Vec2 location) = 0;
    virtual void onTouchCancel (s32 id) = 0;
  };

  struct WindowConfig {
    enum Flag : int {
      Resizable = 1,
      DoubleBuffer = Resizable << 1,
      Default = Resizable | DoubleBuffer;
    };
    std::string name;
    int width;
    int height;
    int color = 8;
    int depth = 24;
    int stencil = 8;
    int samples = 4;
    int flags = Default;
  };

  virtual ~GLView () = 0;
  virtual bool createWindow (Listener *listener, WindowConfig &config);
  virtual void pollEvents () = 0;
  virtual void swapBuffers () = 0;
  virtual void destroyWindow () = 0;
};


CLOSE_JLIB_NS
